package com.maolong.controller;

import com.maolong.pojo.fuction.result.Result;
import com.maolong.pojo.dto.BarcodeDTO;
import com.maolong.pojo.dto.ProdDetailDTO;
import com.maolong.pojo.vo.BarcodeVO;
import com.maolong.service.IProdDetailService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiModelProperty;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletResponse;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author maolong
 * @since 2025-02-09
 */
@Api(tags="商品出入库操作")
@RestController
@RequestMapping("/ProdDetail")
@Slf4j
public class ProdDetailController {
    @Autowired
    IProdDetailService prodDetailService;

    @ApiOperation("上传入库文件")
    @PostMapping("/upload")
    public ResponseEntity<String> upload(@RequestParam("file") MultipartFile file){
        log.info("上传入库文件,参数:{}",file);
        prodDetailService.upload(file);
        return ResponseEntity.ok("上传成功");
    }

    @ApiModelProperty("文件下载")
    @GetMapping("/download")
    public void download(HttpServletResponse response){
        prodDetailService.download(response);
    }

    @ApiModelProperty("商品数据出入库操作")
    @PostMapping("/add")
    public Result add(@RequestBody ProdDetailDTO prodDetailDTO){
        log.info("商品数据出入库操作,参数:{}",prodDetailDTO);
        prodDetailService.save(prodDetailDTO);
        return Result.success();
    }

    @ApiModelProperty("条形码数据出入库操作")
    @PostMapping("/barcodeAdd")
    public Result addBarcode(@RequestBody BarcodeDTO barcodeDTO){
        log.info("条形码数据出入库操作,参数:{}",barcodeDTO);
        BarcodeVO barcodeVO = prodDetailService.updateBarcode(barcodeDTO);
        return Result.success(barcodeVO);
    }

}
